home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / expm.cc < prev    next >
C/C++ Source or Header  |  1996-11-03  |  2KB  |  98 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. // Written by A. S. Hodel <scotte@eng.auburn.edu>
  24.  
  25. #ifdef HAVE_CONFIG_H
  26. #include <config.h>
  27. #endif
  28.  
  29. #include "defun-dld.h"
  30. #include "error.h"
  31. #include "gripes.h"
  32. #include "help.h"
  33. #include "oct-obj.h"
  34. #include "utils.h"
  35.  
  36. DEFUN_DLD (expm, args, ,
  37.   "expm (X): matrix exponential, e^A")
  38. {
  39.   octave_value_list retval;
  40.  
  41.   int nargin = args.length ();
  42.  
  43.   if (nargin != 1)
  44.     {
  45.       print_usage ("expm");
  46.       return retval;
  47.     }
  48.  
  49.   octave_value arg = args(0);
  50.  
  51.   int nr = arg.rows ();
  52.   int nc = arg.columns ();
  53.  
  54.   int arg_is_empty = empty_arg ("expm", nr, nc);
  55.  
  56.   if (arg_is_empty < 0)
  57.     return retval;
  58.   if (arg_is_empty > 0)
  59.     return Matrix ();
  60.  
  61.   if (nr != nc)
  62.     {
  63.       gripe_square_matrix_required ("expm");
  64.       return retval;
  65.     }
  66.  
  67.   if (arg.is_real_type ())
  68.     {
  69.       Matrix m = arg.matrix_value ();
  70.  
  71.       if (error_state)
  72.     return retval;
  73.       else
  74.     retval = m.expm ();
  75.     }
  76.   else if (arg.is_complex_type ())
  77.     {
  78.       ComplexMatrix m = arg.complex_matrix_value ();
  79.  
  80.       if (error_state)
  81.     return retval;
  82.       else
  83.     retval = m.expm ();
  84.     }
  85.   else
  86.     {
  87.       gripe_wrong_type_arg ("expm", arg);
  88.     }
  89.  
  90.   return retval;
  91. }
  92.  
  93. /*
  94. ;;; Local Variables: ***
  95. ;;; mode: C++ ***
  96. ;;; End: ***
  97. */
  98.